/*
 * StrBlob.h
 *
 *  Created on: 2020年11月27日
 *      Author: san
 */

#ifndef STRBLOB_H_
#define STRBLOB_H_

#include <string>
#include <vector>
#include <memory>
#include <exception>
#include <iostream>


class StrBlob {
public:
	friend class StrBlobPtr;
	typedef std::vector<std::string>::size_type size_type;

	// 构造函数和析构函数
	StrBlob();
	StrBlob(std::initializer_list<std::string>);
	StrBlob(const StrBlob&);
	StrBlob& operator=(const StrBlob &);

	virtual ~StrBlob();

	// 运算符重载
	friend bool operator ==(const StrBlob &, const StrBlob &);
	friend bool operator <(const StrBlob &, const StrBlob &);

	// 返回size
	size_type size() const { return data->size();}
	// 判断是否为空
	bool empty() const { return data->empty(); }

	// 增加删除元素
	void push_back(const std::string &t) { data->push_back(t); }
	void push_back(std::string &&t) { std::cout << "push_back_&&" << std::endl; data->push_back(t); };
	void pop_back() { data->pop_back(); }

	// 返回data的引用计数
	unsigned getDataCount() const {return data.use_count();}

	// 元素访问
	std::string front();
	std::string back();

private:
	std::shared_ptr<std::vector<std::string>> data;
	void check(size_type i, const std::string &msg) const;
};

#endif /* STRBLOB_H_ */
